﻿
using KouDai.Phone.Helper;
using KouDai.Phone.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace KouDai.Phone.Parsers
{
    public class HotListParser : BaseParser
    {
        public override void ParseData(string json, Engine.BackData backData)
        {
            List<RankingListEntity> hotListEntities = backData.ResposeData as List<RankingListEntity>;
            JObject jobject = JObject.Parse(json);
            JToken jtoken = jobject.SelectToken("result").SelectToken("datas");
            foreach (JToken jt in jtoken.Children())
            {
                RankingListEntity hotListEntity = new RankingListEntity();
                hotListEntity.Date = jt["date"].ToString();
                hotListEntity.LatestUpdateTime = Convert.ToInt64(jt["latestUpdateTime"].ToString());
                hotListEntity.UpdateTimeTip = jt["updateTimeTip"].ToString();
                hotListEntity.Week = jt["week"].ToString();

                List<HoneyEntity> honeyList = new List<HoneyEntity>();
                JToken subJtoken = jt.SelectToken("items");
                foreach (JToken subJt in subJtoken.Children())
                {
                    HoneyEntity honeyEntity = new HoneyEntity();
                    honeyEntity.ID = subJt["id"].ToString();
                    honeyEntity.FaviorateAmout = Convert.ToInt32(subJt["favoriteAmount"].ToString());
                    honeyEntity.ImageUrlForIphone = subJt["imageUrlForIphone"].ToString();
                    honeyEntity.Url = subJt["imageUrlForIphone"].ToString();
                    honeyList.Add(honeyEntity);
                }
                hotListEntity.HoneyItems = honeyList.ToObservableCollection<HoneyEntity>();
                hotListEntities.Add(hotListEntity);
            }
        }
    }
}
